package com.plz.afmt.controller;

import com.plz.afmt.dto.SysUserDto;
import com.plz.afmt.dto.SysUserLoginDto;
import com.plz.afmt.service.impl.LocalUserServiceImpl;
import com.plz.afmt.vo.SysUserVo;
import com.plz.shrio.dto.BaseLoginDto;
import com.plz.shrio.vo.BaseLoginVo;
import com.plz.web.base.controller.BaseController;
import com.plz.web.base.dto.BaseCodeDto;
import com.plz.web.base.dto.Resp;
import com.plz.web.base.dto.Resq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 登录注册 管理
 * </p>
 *
 * @author jzc
 */
@Slf4j
@RestController
@Api(tags = "登录注册-管理")
@RequestMapping("/base")
public class LoginController extends BaseController {

    @Resource
    private LocalUserServiceImpl localUserService;

    @ApiOperation(value = "后台登录")
    @PostMapping(value = "/login")
    public Resp<BaseLoginVo> sysLogin(@Valid @RequestBody Resq<SysUserLoginDto> requestBean){
        SysUserLoginDto dto = getReqData(requestBean);
        BaseLoginVo result = localUserService.login(dto);
        return getRes(result);
    }

    @ApiOperation(value = "当前登录用户")
    @PostMapping(value = "/me")
    public Resp<BaseLoginVo> me(){
        BaseLoginVo result = localUserService.me();
        return getRes(result);
    }
}
